﻿
using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace ManagoMes.Read.API.Applications.WangDefa
{
    public class StashHtmlHandler : IRequestHandler<StashHtmlCommond, ResultsDTO<Stashs>>
    {

        private
            readonly IBateRepository<Stashs> _Stashs;
        public StashHtmlHandler(IBateRepository<Stashs> stashs )
        {
            _Stashs = stashs;
         
        }

        public async Task<ResultsDTO<Stashs>> Handle(StashHtmlCommond request, CancellationToken cancellationToken)
        {
            try
            {
                var list = new ResultsDTO<Stashs>() { Code = 0 };

                var str = $"select * from warehouselist where 1=1 ";
                var per = new Stashs();
                DapperHelper dapperHelper = new DapperHelper(); 
             
                var result    = _Stashs.GetAll(str, per, dapperHelper.MangoMesRead).ToList();
                if(!string.IsNullOrEmpty(request.StashNum))
                {
                    result = result.Where(x => x.StashNum == request.StashNum).ToList();
                }
                if(!string.IsNullOrEmpty(request.StashName))
                {
                    result = result.Where(x => x.StashName == request.StashName).ToList();
                }

                list.Data = result;

                return list;
            }
            catch (Exception)
            {

                throw;
            }
            
        }
    }
}
